package servlet.materiales;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.servlet.RequestDispatcher;

import dao.MaterialesDAO;
import excepcion.DAOExcepcion;
import modelo.Materiales;

/**
 * Servlet implementation class MaterialesModificarServlet
 */
@WebServlet("/MaterialesModificarServlet")
public class MaterialesModificarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MaterialesModificarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String a = request.getParameter("nombre");
		String x = request.getParameter("stock");
		Integer ax= Integer.parseInt(x);
		String y = request.getParameter("costoPromedioUnitario");
		Double bx= Double.parseDouble(y);
		String b = request.getParameter("descripcion");
		String c = request.getParameter("leadTime");
		Integer cx= Integer.parseInt(c);

		Materiales vo = new Materiales();
		vo.setNombre(a);
		vo.setStock(ax);
		vo.setCostoPromedioUnitario(bx);
		vo.setDescripcion(b);
		vo.setLeadTime(cx);

		MaterialesDAO dao = new MaterialesDAO();
		try {
			dao.actualizar(vo);
			response.sendRedirect(request.getContextPath()
					+ "/MaterialesBuscarServlet");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
